package com.ruoyi.fly.service.impl;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.fly.domain.ServerCategory;
import com.ruoyi.fly.domain.vo.ServerCategorySearchVo;
import com.ruoyi.fly.domain.vo.ServerCategoryVo;
import com.ruoyi.fly.mapper.ServerCategoryMapper;
import com.ruoyi.fly.service.ServerCategoryService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ServerCategoryServiceImpl implements ServerCategoryService {

    @Autowired
    private ServerCategoryMapper serverCategoryMapper;

    /**
     * 查询服务分类
     *
     * @param id 服务分类主键
     * @return
     */
    @Override
    public ServerCategory selectServerCategoryById(String id) {
        return serverCategoryMapper.selectServerCategoryById(id);
    }

    /**
     * 查询服务分类列表
     *
     * @param serverCategorySearchVo 服务分类
     * @return
     */
    @Override
    public List<ServerCategory> selectServerCategoryPage(ServerCategorySearchVo serverCategorySearchVo) {
        ServerCategory serverCategory = new ServerCategory();
        BeanUtils.copyProperties(serverCategorySearchVo, serverCategory);
        return serverCategoryMapper.selectServerCategoryPage(serverCategory);
    }

    @Override
    public List<ServerCategory> selectServerCategoryList(ServerCategory serverCategory) {
        return serverCategoryMapper.selectServerCategoryList(serverCategory);
    }

    /**
     * 新增服务分类
     *
     * @param serverCategory 服务分类
     * @return
     */
    @Override
    public R insertServerCategory(ServerCategory serverCategory) {
        serverCategory.setCreateBy(String.valueOf(SecurityUtils.getUserId()));
        return serverCategoryMapper.insertServerCategory(serverCategory) > 0 ? R.ok("新增成功") : R.fail("操作失败");
    }

    /**
     * 上架
     *
     * @param serverCategoryVo
     * @return
     */
    @Override
    public R onlineProduct(ServerCategoryVo serverCategoryVo) {
        return serverCategoryMapper.onlineServerCategory(serverCategoryVo.getId()) > 0 ? R.ok("上架成功") : R.fail("操作失败");
    }

    /**
     * 下架
     *
     * @param serverCategoryVo
     * @return
     */
    @Override
    public R offlineProduct(ServerCategoryVo serverCategoryVo) {
        return serverCategoryMapper.offlineServerCategory(serverCategoryVo.getId()) > 0 ? R.ok("下架成功") : R.fail("操作失败");
    }

    /**
     * 修改服务分类
     *
     * @param serverCategory 服务分类
     * @return
     */
    @Override
    public R updateServerCategory(ServerCategory serverCategory) {
        serverCategory.setUpdateUser(String.valueOf(SecurityUtils.getUserId()));
        return serverCategoryMapper.updateServerCategory(serverCategory) > 0 ? R.ok("修改成功") : R.fail("操作失败");
    }

    @Override
    public R deleteServerCategoryById(String id) {
        return serverCategoryMapper.deleteServerCategoryById(id) > 0 ? R.ok("删除成功") : R.fail("操作失败");
    }

    @Override
    public R deleteServerCategoryByIds(String[] ids) {
        return serverCategoryMapper.deleteServerCategoryByIds(ids) > 0 ? R.ok("删除成功") : R.fail("操作失败");
    }
}
